package mh.entity;

import java.util.ArrayList;

/**
 * Contains all avaible state for each entity.
 * 
 * @author Gianmarco Laggia
 * @author Alberto D'Este
 */
public enum EnumState{
	/**
	 * DAMAGE STATE<br>
	 * Main state of each object [REQUIRED]. The object uses this state when has not received any damage, nor is burned
	 * or blasted and has no special render to do. This state is only about damage.
	 */
	INTACT(1,true),
	/**
	 * DAMAGE STATE<br>
	 * If the health of the entity is not at its maximum value. The render shows signs of damaging in the object. (also
	 * animated)
	 */
	DAMAGED(2,true),
	/**
	 * DAMAGE STATE<br>
	 * If the health of the entity is equals to zero.
	 */
	BROKEN(3,true),
	/**
	 * DAMAGE STATE<br>
	 * If the entity has been blasted
	 */
	BLASTED(4,true),

	/**
	 * ANIMATION STATE<br>
	 * If the entity is animating a blast.
	 */
	BLASTING_OUT(203,false),
	/**
	 * ANIMATION STATE<br>
	 * If an entity that was blasted is animating its repair.
	 */
	BLASTING_IN(204,false),
	/**
	 * DAMAGE STATE<br>
	 * If the entity is burned. The render put on the entity at random time some smoke.
	 */
	BURNED(5,true),

	/**
	 * A state that is added to a damage state. If the entity is in the open state, the render shows the object with its
	 * opening part open.
	 */
	OPEN(101,false),
	/**
	 * Added to a damage state, the entity is nearly open.
	 */
	MID_OPEN(109,false),
	/**
	 * Added to a damage state, the entity is nearly closed.
	 */
	MID_CLOSED(110,false),
	/** The opposite of {@link #OPEN} */
	CLOSED(102,false),
	/**
	 * A state that is added to a damage state. If the entity can open but is protected to do so. The render shows the
	 * animation that occurs if you try to open a locked object
	 */
	LOCKED(103,false),
	/** A state that is added to a damage state. If the entity is burning. The render put on the entity some flames */
	BURNING(104,false),
	/** A state that is added to a damage state. Put a grey layer on the entity */
	DUSTY(105,false),
	/** A state that is added to a damage state. Shows signs of wetting */
	WET(106,false),
	/** A state that is added to a damage state. Put the entity "into" the ice */
	FROZEN(107,false),
	/** A state that is added to a damage state. Put some writing on the entity */
	WRITTEN(108,false),

	/** A state that is added to a damage state. Simulate the act of flying of the entity */
	FLOATING(201,false),
	/** The entity is invisible */
	HIDDEN(202,false),

	/** Default state */
	NOT_FOUND(0,false)

	;

	private int		stateIndex;
	private boolean	isDamage;

	private EnumState(int stateIndex, boolean isDamageState) {
		this.stateIndex = stateIndex;
		this.isDamage = isDamageState;
	}

	/**
	 * @param stateIndex
	 * @return The EnumState that corresponds to the given index
	 */
	public static EnumState getState(int stateIndex) {
		for (EnumState l : EnumState.values()) {
			if (l.stateIndex == stateIndex) {
				return l;
			}
		}
		return EnumState.NOT_FOUND;
	}

	/**
	 * @return True if the state is a damage state.
	 */
	public boolean isDamageState() {
		return this.isDamage;
	}

	/**
	 * @return A list of all the avaible damage states.
	 */
	public static ArrayList<EnumState> getDamageStates() {
		ArrayList<EnumState> ret = new ArrayList<EnumState>();
		for (EnumState s : EnumState.values()) {
			if (s.isDamageState()) {
				ret.add(s);
			}
		}
		return ret;
	}

	public int toInt() {
		return this.stateIndex;
	}

}
